package jzqb.dao.impl;

import cnki.tpi.kbatis.sqlsession.SqlSession;
import cnki.tpi.kbatis.utils.DataSourceUtil;
import jzqb.bo.CommonsBo;
import jzqb.dao.ICommonsDao;
import jzqb.po.CommonsPo;
import jzqb.vo.CommonsVo;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Description:
 *
 * @author BaiGe
 * @date: 2021/4/7 14:31
 * @Version 1.0
 */
@Repository
public class CommonsDaoImpl implements ICommonsDao {
    @Override
    public List<CommonsVo> queryCommonsList(CommonsBo commonsBo) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.ICommonsDao.queryCommonsList";
        return sqlSession.selectList(statementId, commonsBo, false);
    }

    @Override
    public long queryCommonsCount(CommonsBo commonsBo) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.ICommonsDao.queryCommonsCount";
        return sqlSession.getCount(statementId, commonsBo);
    }

    @Override
    public Boolean updateCommons(CommonsPo commonsPo) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.ICommonsDao.updateCommons";
        return sqlSession.executeUpdate(statementId, commonsPo);
    }

    @Override
    public Boolean delCommonsById(Integer id) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.ICommonsDao.delCommonsById";
        return sqlSession.executeDelete(statementId, id);
    }

    @Override
    public List<CommonsVo> queryOwnCommonsList(CommonsBo commonsBo) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.ICommonsDao.queryOwnCommonsList";
        return sqlSession.selectList(statementId, commonsBo, false);
    }

    @Override
    public long queryOwnCommonsCount(CommonsBo commonsBo) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.ICommonsDao.queryOwnCommonsCount";
        return sqlSession.getCount(statementId,commonsBo);
    }

    @Override
    public Boolean addCommons(CommonsPo commonsPo) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.ICommonsDao.addCommons";
        return sqlSession.executeInsert(statementId, commonsPo);
    }

    @Override
    public Boolean updateCommonsReadStatus(CommonsPo commonsPo) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.ICommonsDao.updateCommonsReadStatus";
        return sqlSession.executeUpdate(statementId, commonsPo);
    }

    @Override
    public long getUnReadCommonsNum(CommonsBo commonsBo) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.ICommonsDao.getUnReadCommonsNum";
        return sqlSession.getCount(statementId, commonsBo);
    }
}
